 <?php
class Company extends CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return "mt_company";
    }
    
    public function attributeLabels() {
        return array(
            "company_name_thai" => "ชื่อองค์กรภาษาไทย",
            "company_name_eng" => "ชื่อองค์กรภาษาอังกฤษ",
            "company_address_thai" => "ที่อยู่องค์กรภาษาไทย",
            "company_address_eng" => "ที่อยู่องค์กรภาษาอังกฤษ",
            "company_email" => "email",
            "company_tel" => "เบอร์โทรศัพท์",
            "company_description" => "รายละเอียด",
            "company_status" => "สถานะ",
            "company_create_date" => "วันที่สร้าง",
            "company_modified_date" => "วันที่แก้ไข",
        );
    }
    
    public function rules() {
        return array(
            array("company_name_thai, company_name_eng,company_address_thai,company_address_eng,company_email,company_tel", "required",'message'=>'กรุณากรอกข้อมูลให้ครบ'),
            array("company_name_thai", "length", "max" => 255),
            array("company_name_eng", "length", "max" => 255),
            array("company_address_thai", "length", "max" => 255),
            array("company_address_eng", "length", "max" => 255),
            array("company_email", "length", "max" => 100),
            array("company_tel", "length", "max" => 10),
            array('company_tel', 'numerical', 'integerOnly'=>true)
        );
    }
    
    public function search() {
        $criteria = new CDbCriteria;
        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }
    
    public function beforeValidate() {
        if ($this->isNewRecord) {
            $this->company_status = 1;
            $this->company_create_date = new CDbExpression("NOW()");
        }
        else
        {
            $this->company_modified_date = new CDbExpression("NOW()");
        }

        return parent::beforeValidate();
    }
}
?>
